//
//  StoreViewController.m
//  shopping
//
//  Created by 徐双 on 2017/9/13.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "StoreViewController.h"
#import "StoreViewCell.h"

@interface StoreViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView * tableView;
@property (nonatomic, strong) NSMutableArray *datarr;
@end

@implementation StoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creationDate];
    UIView *viewOf = [[UIView alloc] init];
    viewOf.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, 1);
    [self.view addSubview:viewOf];
    viewOf.backgroundColor = [UIColor colorWithRed:204 / 255.0f green:204 / 255.0f  blue:204 / 255.0f  alpha:1];
    
    self.tableView = [[UITableView alloc] init];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.frame = CGRectMake(0, 1, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 65);
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    self.tableView.separatorStyle = UITableViewCellAccessoryNone;//去掉分割线

    [self.tableView registerNib:[UINib nibWithNibName:@"StoreViewCell" bundle:nil] forCellReuseIdentifier:@"StoreViewCell"];
}
- (void)creationDate{
    
    _datarr = [[NSMutableArray alloc] init];
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    //NSString *token = @"31921bdfb836a4814a272e96004aaa25656";
    
    [productParams setValue:token forKey:@"token"];
    
    [[MNetworkHandler sharedInstance]conURL:adminFavoritesgetgetGoodSeed networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            _datarr = [returnData objectForKey:@"data"];
            
            
            
            NSLog(@"!!!!!!!!!!!!!!!%@", _datarr);
            
            [self.tableView reloadData];
            
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return self.datarr.count;
    //return 3;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 68;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    StoreViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"StoreViewCell"];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSMutableDictionary *dic = self.datarr[indexPath.row];
    
    NSString *urlN=manage(AP_Img, [dic objectForKey:@"shopImg"]);
    [cell.shopImg sd_setImageWithURL:[NSURL URLWithString:urlN] placeholderImage:[UIImage imageNamed:@""]];
    cell.shopName.text = [dic objectForKey:@"shopName"];
    
    return cell;
}



@end
